package com.tw.trips.ui;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Service;

import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.VerticalSplitPanel;
import com.vaadin.ui.themes.BaseTheme;

@Service
@Configurable(preConstruction = true)

public class HomeSplitLayout extends VerticalLayout {
public GridLayout grid;
public static final String brownFox = "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. ";
	public HomeSplitLayout() {
		 // First a vertical SplitPanel
        final VerticalSplitPanel vert = new VerticalSplitPanel();
        vert.setHeight("450px");
        vert.setWidth("100%");
        vert.setSplitPosition(150, Sizeable.UNITS_PIXELS);
        addComponent(vert);

        // add a label to the upper area
        vert.addComponent(new Label(brownFox));

        // Add a horizontal SplitPanel to the lower area
        final HorizontalSplitPanel horiz = new HorizontalSplitPanel();
        horiz.setSplitPosition(50); // percent
        vert.addComponent(horiz);

        // left component:
        horiz.addComponent(new Label(brownFox));

        // right component:
        horiz.addComponent(new Label(brownFox));

        // Lock toggle button
        CheckBox toggleLocked = new CheckBox("Splits locked",
                new Button.ClickListener() {
                    // inline click.listener
                    public void buttonClick(ClickEvent event) {
                        vert.setLocked(event.getButton().booleanValue());
                        horiz.setLocked(event.getButton().booleanValue());
                    }
                });
        toggleLocked.setImmediate(true);
        addComponent(toggleLocked);

    }


	private Panel getOthersPanel() {
		Panel panel = new Panel();
		panel.setHeight("100%");
		panel.setWidth("25%");
		
		return panel;
	}

	private Panel getContentPane() {
		Panel panel = new Panel();
		panel.setHeight("100%");
		panel.setWidth("100%");
		
		return panel;
	}

	private Panel getLinksPanel() {
		Panel panel = new Panel();
		panel.setHeight("100%");
		panel.setWidth("25%");
		VerticalLayout vertLayout = (VerticalLayout) panel.getContent();
		
		
		Button trips = new Button("Trips");
		trips.setStyleName(BaseTheme.BUTTON_LINK);
		trips.setDescription("Lists your trips!");
		trips.addListener(new Button.ClickListener() {
			
			public void buttonClick(ClickEvent event) {
				// TODO Auto-generated method stub
				
			}
		}); 
		
		Button alerts = new Button("Alerts1");
		alerts.setStyleName(BaseTheme.BUTTON_LINK);
		alerts.setDescription("Alerts for your Trip!");
		alerts.addListener(new Button.ClickListener() {
			
			public void buttonClick(ClickEvent event) {
				// TODO Auto-generated method stub
				
			}
		}); 
		
		
		Button locations = new Button("Locations");
		locations.setStyleName(BaseTheme.BUTTON_LINK);
		locations.setDescription("Your Locations!");
		locations.addListener(new Button.ClickListener() {
			
			public void buttonClick(ClickEvent event) {
				// TODO Auto-generated method stub
				
			}
		}); 
		
		
		Button updates = new Button("Updates");
		updates.setStyleName(BaseTheme.BUTTON_LINK);
		updates.setDescription("Your Updates!");
		updates.addListener(new Button.ClickListener() {
			
			public void buttonClick(ClickEvent event) {
				System.out.println("Update Link Clicked");
				grid.removeComponent(1, 1);
				grid.addComponent(new UpdatePane(),1,1);
				
			}
		}); 
		
		
		vertLayout.addComponent(trips);
		vertLayout.setComponentAlignment(trips, Alignment.MIDDLE_LEFT);
		vertLayout.addComponent(alerts);
		vertLayout.setComponentAlignment(alerts, Alignment.MIDDLE_LEFT);
		vertLayout.addComponent(locations);
		vertLayout.setComponentAlignment(locations, Alignment.MIDDLE_LEFT);
		vertLayout.addComponent(updates);
		vertLayout.setComponentAlignment(updates, Alignment.MIDDLE_LEFT);
		
		
		return panel;
		
	}

	private Panel getHeader(String content, Alignment alignment) {
		Panel panel = new Panel();
		VerticalLayout vertLayout = (VerticalLayout) panel.getContent();
		Label label = new Label(content);
		panel.addComponent(label);

		vertLayout.addComponent(label);
		vertLayout.setComponentAlignment(label, alignment);
		return panel;
	}
}
